<template>
  <el-dialog :visible="visible" @close="closeDialog" :title="title"
             top="auto"
             :modal="true"
             width="70%"
             append-to-body
             :close-on-click-modal="false"
  >
    <el-form
      ref="editForm"
      :model="form"
      :rules="rules"
      label-width="240px"
      label-position="right"
      
      :disabled="disabledStop"
      
    >
      <el-row>
        <el-col :span="12">
          <el-form-item prop="assetTagNumber" label="固定资产标签编号">
            <el-input
              v-model="form.assetTagNumber"
              show-word-limit
              placeholder="固定资产标签编号"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item prop="cloudCenterAssetTag" label="云中心资产标签">
            <el-input
              v-model="form.cloudCenterAssetTag"
              show-word-limit
              placeholder="云中心资产标签"
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item prop="noticeAssetNumber" label="固定资产增加通知单固定资产编号">
            <el-input v-model="form.noticeAssetNumber" show-word-limit placeholder="固定资产增加通知单固定资产编号"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item prop="noticeNumber" label="固定资产增加通知单编号">
            <el-input v-model="form.noticeNumber" placeholder="固定资产增加通知单编号"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item prop="sysCardNumber" label="固定资产管理系统卡片号">
            <el-input v-model="form.sysCardNumber" placeholder="固定资产管理系统卡片号"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item prop="sysCardUniqueNumber" label="固定资产管理系统卡片唯一编号">
            <el-input v-model="form.sysCardUniqueNumber" placeholder="固定资产管理系统卡片唯一编号"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item prop="sysDirectoryCode" label="固定资产管理系统目录代码">
            <el-input v-model="form.sysDirectoryCode" placeholder="固定资产管理系统目录代码"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item prop="assetClassify" label="资产分类">
            <el-select v-model="form.assetClassify" size="small" placeholder="资产分类" style="width:100%" clearable>
              <el-option
                v-for="dict in dict.type.fa_asset_classify"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item prop="classify" label="分类">
            <el-select v-model="form.classify" size="small" placeholder="分类" style="width:100%" clearable>
              <el-option
                v-for="dict in dict.type.fa_classify"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item prop="deviceName" label="设备名称">
            <el-input v-model="form.deviceName" placeholder="设备名称"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item prop="brand" label="品牌">
            <el-input v-model="form.brand" placeholder="品牌"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item prop="deviceType" label="设备类型">
            <el-select v-model="form.deviceType" size="small" placeholder="设备类型" style="width:100%" clearable>
              <el-option
                v-for="dict in dict.type.fa_device_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item prop="deviceModel" label="设备型号">
            <el-input v-model="form.deviceModel" placeholder="设备型号"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item prop="deviceSpec" label="设备规格">
            <el-input v-model="form.deviceSpec" placeholder="设备规格"></el-input>
          </el-form-item>
        </el-col>
        
      </el-row>


      <el-row>
        <el-col :span="12">
          <el-form-item prop="serialNumber" label="序列号">
            <el-input v-model="form.serialNumber" placeholder="序列号"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item prop="quantity" label="数量">
            <el-input v-model="form.quantity" placeholder="数量"></el-input>
          </el-form-item>
        </el-col>
        
      </el-row>


      <el-row>
        <el-col :span="12">
          <el-form-item prop="unit" label="单位">
            <el-input v-model="form.unit" placeholder="单位"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item prop="amount" label="金额">
            <el-input v-model="form.amount" placeholder="金额"></el-input>
          </el-form-item>
        </el-col>
        
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item prop="importance" label="重要程度">
            <el-input v-model="form.importance" placeholder="重要程度"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item prop="detailedAccountVoucherNumber" label="固定资产明细账凭单号">
            <el-input v-model="form.detailedAccountVoucherNumber" placeholder="固定资产明细账凭单号"></el-input>
          </el-form-item>
        </el-col>
        
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item prop="peopleUse" label="使用人">
            <el-input v-model="form.peopleUse" placeholder="使用人"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item prop="preserver" label="保管人">
            <el-input v-model="form.preserver" placeholder="保管人"></el-input>
          </el-form-item>
        </el-col>
       
      </el-row>

      <el-row>
         <el-col :span="12">
          <el-form-item prop="claimingDate" label="领用日期">
            <el-date-picker v-model="form.claimingDate" style="width:100%" placeholder="领用日期" value-format="yyyy-MM-dd"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item prop="officeSpace" label="办公场所">
            <el-input v-model="form.officeSpace" placeholder="办公场所"></el-input>
          </el-form-item>
        </el-col>
        
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item prop="storageArea" label="存放区域">
            <el-input v-model="form.storageArea" placeholder="存放区域"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">

          <el-form-item prop="detailedLocation" label="详细位置">
            <el-input v-model="form.detailedLocation" placeholder="详细位置"></el-input>
          </el-form-item>
        </el-col>
        
      </el-row>


      <el-row>
        <el-col :span="12">
          <el-form-item prop="source" label="来源">
            <el-input v-model="form.source" placeholder="来源"></el-input>
          </el-form-item>

        </el-col>
        <el-col :span="12">
          <el-form-item prop="organizationalPurchasingForm" label="组织采购形式">
            <el-select v-model="form.organizationalPurchasingForm" size="small" placeholder="组织采购形式" style="width:100%"
                       clearable
            >
              <el-option
                v-for="dict in dict.type.fa_organizational_purchasing_form"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        
      </el-row>


      <el-row>
        <el-col :span="12">
          <el-form-item prop="originalOwner" label="原领用人">
            <el-input v-model="form.originalOwner" placeholder="原领用人"></el-input>
          </el-form-item>

        </el-col>
        <el-col :span="12">
          <el-form-item prop="discRepletion" label="盘实">
            <el-input v-model="form.discRepletion" placeholder="盘实"></el-input>
          </el-form-item>
        </el-col>
        
      </el-row>


      <el-row>
        <el-col :span="12">
          <el-form-item prop="tag" label="标签">
            <el-input v-model="form.tag" placeholder="标签"></el-input>
          </el-form-item>

        </el-col>
        <el-col :span="12">
          <el-form-item prop="status" label="设备状态">
            <el-select v-model="form.status" size="small" placeholder="设备状态" style="width:100%" clearable>
              <el-option
                v-for="dict in dict.type.fa_status"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        
      </el-row>


      <el-row>
        <el-col :span="12">
          <el-form-item prop="retirementLife" label="报废年限">
            <el-input v-model="form.retirementLife" placeholder="报废年限"></el-input>
          </el-form-item>

        </el-col>
        <el-col :span="12">
          <el-form-item prop="disposalScheme" label="处置方案">
            <el-select v-model="form.disposalScheme" size="small" placeholder="处置方案" style="width:100%" clearable>
              <el-option
                v-for="dict in dict.type.fa_disposal_scheme"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        
      </el-row>


      <el-row>
        <el-col :span="12">
          <el-form-item prop="department" label="所属部门">
            <el-select v-model="form.department" size="small" placeholder="所属部门" style="width:100%"
                       clearable
            >
              <el-option
                v-for="item in deptOptions"
                :key="item.deptId"
                :label="item.deptName"
                :value="item.deptName">
              </el-option>
            </el-select>
          </el-form-item>

        </el-col>
        <el-col :span="12">
          <el-form-item prop="disposalPriority" label="处置优先级">
            <el-select v-model="form.disposalPriority" size="small" placeholder="处置优先级" style="width:100%" clearable>
              <el-option
                v-for="dict in dict.type.fa_disposal_priority"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item prop="retirementDate" label="报废日期">
            <el-date-picker v-model="form.retirementDate" style="width:100%" placeholder="报废日期"
                            value-format="yyyy-MM-dd"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item prop="retirementStatus" label="报废状态">
            <el-select v-model="form.retirementStatus" size="small" placeholder="报废状态" style="width:100%" clearable>
              <el-option
                v-for="dict in dict.type.fa_retirement_status"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item prop="remark" label="备注">
            <el-input v-model="form.remark" placeholder="备注"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <template slot="footer">
      <el-button @click="handleCancel">取 消</el-button>
      <el-button v-if="!disabledStop" :loading="loading" type="primary" @click="handleSubmit">保 存</el-button>
      <el-button v-else :loading="loading" type="primary" @click="closeDialog">返 回</el-button>
    </template>
  </el-dialog>
</template>

<script>
import { insert, edit } from '@/api/bizFixAssets/bizFixAssetsApi.js'
import Common from '@/utils/common'

export default {
  mixins: [Common],
  props:{
    deptOptions:{
      type:Array,
      
    }
  },
  dicts: ['fa_device_type', 'fa_asset_classify', 'fa_classify', 'fa_organizational_purchasing_form', 'fa_status', 'fa_disposal_scheme', 'fa_disposal_priority', 'fa_retirement_status'],
  data() {
    return {
      visible: false,
      loading: false,
      isEdit: false,
      disabledStop: false,
      title:'',
      form: {
        
      },
      rules: {
        assetTagNumber: [{ required: true, message: '固定资产标签编号不能为空', trigger: 'blur' }],
        cloudCenterAssetTag: [{ required: false, message: '不能为空', trigger: 'blur' }],
        noticeAssetNumber: [{ required: false, message: '不能为空', trigger: 'blur' }],
        noticeNumber: [{ required: false, message: '不能为空', trigger: 'blur' }],
        sysCardNumber: [{ required: false, message: '不能为空', trigger: 'blur' }],
        sysCardUniqueNumber: [{ required: false, message: '不能为空', trigger: 'blur' }],
        sysDirectoryCode: [{ required: false, message: '不能为空', trigger: 'blur' }],
        assetClassify: [{ required: false, message: '不能为空', trigger: 'blur' }],
        classify: [{ required: false, message: '不能为空', trigger: 'blur' }],
        deviceName: [{ required: false, message: '不能为空', trigger: 'blur' }],
        brand: [{ required: false, message: '不能为空', trigger: 'blur' }],
        deviceType: [{ required: false, message: '不能为空', trigger: 'blur' }],
        deviceModel: [{ required: false, message: '不能为空', trigger: 'blur' }],
        deviceSpec: [{ required: false, message: '不能为空', trigger: 'blur' }],
        serialNumber: [{ required: false, message: '不能为空', trigger: 'blur' }],
        quantity: [{ required: false, message: '不能为空', trigger: 'blur' }],
        unit: [{ required: false, message: '不能为空', trigger: 'blur' }],
        amount: [{ required: false, message: '不能为空', trigger: 'blur' }],
        importance: [{ required: false, message: '不能为空', trigger: 'blur' }],
        detailedAccountVoucherNumber: [{ required: false, message: '不能为空', trigger: 'blur' }],
        peopleUse: [{ required: false, message: '不能为空', trigger: 'blur' }],
        preserver: [{ required: false, message: '不能为空', trigger: 'blur' }],
        claimingDate: [{ required: false, message: '不能为空', trigger: 'blur' }],
        officeSpace: [{ required: false, message: '不能为空', trigger: 'blur' }],
        storageArea: [{ required: false, message: '不能为空', trigger: 'blur' }],
        detailedLocation: [{ required: false, message: '不能为空', trigger: 'blur' }],
        source: [{ required: false, message: '不能为空', trigger: 'blur' }],
        organizationalPurchasingForm: [{ required: false, message: '不能为空', trigger: 'blur' }],
        originalOwner: [{ required: false, message: '不能为空', trigger: 'blur' }],
        discRepletion: [{ required: false, message: '不能为空', trigger: 'blur' }],
        tag: [{ required: false, message: '不能为空', trigger: 'blur' }],
        status: [{ required: false, message: '不能为空', trigger: 'blur' }],
        retirementLife: [{ required: false, message: '不能为空', trigger: 'blur' }],
        disposalScheme: [{ required: false, message: '不能为空', trigger: 'blur' }],
        department: [{ required: false, message: '不能为空', trigger: 'blur' }],
        disposalPriority: [{ required: false, message: '不能为空', trigger: 'blur' }],
        retirementDate: [{ required: false, message: '不能为空', trigger: 'blur' }],
        createBy: [{ required: false, message: '不能为空', trigger: 'blur' }],
        createTime: [{ required: false, message: '不能为空', trigger: 'blur' }],
        updateBy: [{ required: false, message: '不能为空', trigger: 'blur' }],
        updateTime: [{ required: false, message: '不能为空', trigger: 'blur' }],
        // remark: [{ required: false, message: '不能为空', trigger: 'blur' }],
        retirementStatus:[{ required: false, message: '不能为空', trigger: 'blur' }]
      }
    }
  },

  computed: {
    formRef() {
      return this.$refs.editForm
    }
  },
  methods: {
    closeDialog(){
      this.$refs.editForm.resetFields();
      this.form={}
      this.loading = false
      this.visible = false
    },
    show(info,falg) {
      
      if (!info) {
        this.title = '新增固定资产'
        this.visible = true
          this.disabledStop = false
           this.isEdit = false
          this.form = {}
      } else {
        if (falg == 1) {
          this.title = '查看固定资产详细'
          this.disabledStop = true
        } else {
          this.title = '编辑固定资产'
          this.disabledStop = false
        }
        
        this.visible = true
         this.isEdit = true
         
        this.form={...info}
         
      }
     
      
    },
    handleSubmit() {
      this.formRef.validate(async(valid) => {
        if (valid) {
          this.loading = true
          this.disabledStop = true
          const callApi = this.isEdit ? edit : insert
          const res = await callApi(this.form)
          this.loading = false
          this.disabledStop = false
          if (res.code !== 200) {
            this.error(res.msg)
            return
          }
          this.$emit('refresh')
          this.success('操作成功')
          this.handleCancel()
        }
      })
    },
    handleCancel() {
     this.$refs.editForm.resetFields();
     this.form={}
      this.loading = false
      this.disabledStop = false
      this.visible = false
    }
  }
}
</script>

<style lang="scss">
el-dialog {
  background: #ffffff;
  border: 1px solid #ffffff;
}

</style>
